<!doctype html>
<html>
<head>
<script src="qrc:///js/bignumber.min.js"></script>
<script src="qrc:///js/webthree.js"></script>
<script src="qrc:///qml/js/Printer.js"></script>
<script src="qrc:///qml/js/ansi2html.js"></script>
<script>
loadPage = function(url) {
	var preview = document.getElementById('preview');
	preview.src = url;

};

reloadPage = function() {
	var preview = document.getElementById('preview');
	preview.contentWindow.location.reload();
};

updateContracts = function(contracts) {
	if (window.web3) {
		window.web3.reset();
		window.contracts = {};
		window.BigNumber = require('bignumber.js');
		for (var c in contracts) {
			var contract = window.web3.eth.contract(contracts[c].interface).at(contracts[c].address);
			window.contracts[c] = {
				address: contracts[c].address,
				interface: contracts[c].interface,
				contract: contract
			};
		}
	}
};

init = function(url) {
	web3 = require('web3');
	window.web3 = web3;
	web3.setProvider(new web3.providers.HttpProvider(url));
};

executeJavaScript = function(script) {
	var preview = document.getElementById('preview');
	var obj = preview.contentWindow.eval(script);
	var printed = prettyPrint(obj);
	return ansi2html(printed);
}

getContent = function() {
	var preview = document.getElementById('preview');
	var doc = preview.contentDocument? preview.contentDocument: preview.contentWindow.document;
	var body = doc.getElementsByTagName('body')[0];
	return body.innerHTML;
}

</script>

<style>
body {
	margin: 0;
}
</style>

</head>
<body><iframe src="" name="preview" id="preview" style="border: 0; position:absolute; top:0; left:0; right:0; bottom:0; width:100%; height:100%"></iframe></body>
</html>
